<template>
  <div class="app-container">
    <!-- 顶部控制台 -->
    <div class="filter-container">
      <el-select class="filter-item" style="width: 160px" size="mini" v-model="form.searchReason" placeholder="请选择举报原因" @change="handlePageInit">
        <el-option v-for="item in pageData.searchReasonList" :key="item.value" :label="item.label" :value="item.value"/>
      </el-select>
      <el-select class="filter-item" style="width: 160px" size="mini" v-model="form.searchStatus" placeholder="请选择处理结果" @change="handlePageInit">
        <el-option v-for="item in pageData.searchStatusList" :key="item.value" :label="item.label" :value="item.value"/>
      </el-select>
      <el-select class="filter-item" style="width: 160px" size="mini" v-model="form.searchType" placeholder="请选择被举报类型" @change="handlePageInit">
        <el-option v-for="item in pageData.searchTypeList" :key="item.value" :label="item.label" :value="item.value"/>
      </el-select>
    </div>
    <!--数据列表-->
    <div class="data-table">
      <el-table :data="responseData.tableList"
                border style="width: 100%;"
                v-loading="pageData.loading"
                element-loading-text="拼命加载中"
                element-loading-spinner="el-icon-loading"
                element-loading-background="rgba(0, 0, 0, 0.8)"
                :header-cell-style="{ background: '#545C64', color: '#ffffff' }"
                @selection-change="handleTableSelection">
        <el-table-column type="selection" width="55" align="center"/>
        <el-table-column fixed="left" prop="reportId" label="举报ID" width="320" align="center"></el-table-column>
        <el-table-column prop="reportType" label="举报类型" width="120" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.reportType === 1"><el-tag type="warning">举报提问</el-tag></span>
            <span v-if="scope.row.reportType === 2"><el-tag type="success">举报回答</el-tag></span>
            <span v-if="scope.row.reportType === 3"><el-tag type="primary">举报评论</el-tag></span>
          </template>
        </el-table-column>
        <el-table-column prop="reportStatus" label="审核状态" width="120" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.reportStatus === 0"><el-tag type="warning">未审核</el-tag></span>
            <span v-if="scope.row.reportStatus === 1"><el-tag type="success">已审核</el-tag></span>
            <span v-if="scope.row.reportStatus === 2"><el-tag type="primary">已处理</el-tag></span>
          </template>
        </el-table-column>
        <el-table-column prop="reportTargetTitle" label="举报内容" width="320" align="center">
          <template slot-scope="scope">
            <span class="link-type" v-if="scope.row.reportStatus === 0" @click="handleOpenReportDisposePanel(scope)">{{ scope.row.reportTargetTitle }}</span>
            <span class="link-type" v-else>{{ scope.row.reportTargetTitle }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="reportUserName" label="举报用户" width="180" align="center"></el-table-column>
        <el-table-column prop="reportDisposeUser" label="处理用户" width="120" align="center"></el-table-column>
        <el-table-column prop="reportProcessMode" label="处理方式" width="120" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.reportProcessMode === 0"><el-tag type="warning">仅阅读</el-tag></span>
            <span v-if="scope.row.reportProcessMode === 1"><el-tag type="success">删除内容</el-tag></span>
            <span v-if="scope.row.reportProcessMode === 2"><el-tag type="primary">禁言3天</el-tag></span>
            <span v-if="scope.row.reportProcessMode === 3"><el-tag type="info">禁言7天</el-tag></span>
            <span v-if="scope.row.reportProcessMode === 4"><el-tag type="warning">禁言30天</el-tag></span>
            <span v-if="scope.row.reportProcessMode === 5"><el-tag type="success">终身禁言</el-tag></span>
            <span v-if="scope.row.reportProcessMode === 6"><el-tag type="primary">冻结商户</el-tag></span>
          </template>
        </el-table-column>
        <el-table-column prop="reportCreateTime" label="举报时间" width="240" align="center"></el-table-column>
        <el-table-column prop="reportDisposeTime" label="处理时间" width="240" align="center"></el-table-column>
        <el-table-column fixed="right" label="操作" width="240" align="center">
          <template slot-scope="scope">
            <el-button type="success" size="small" v-if="scope.row.reportStatus === 0" @click="handleOpenReportDisposePanel(scope)">处理</el-button>
            <el-button type="info" size="small" v-if="scope.row.reportStatus !== 0" disabled>处理</el-button>
            <el-button type="danger" size="small">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!--分页器-->
    <div style="margin-top: 20px">
      <div class="block" style="width: 100%; text-align: center">
        <el-pagination
          layout="total, sizes, prev, pager, next, jumper"
          :current-page="form.pageNum"
          :page-size="form.pageSize"
          :total="form.total"
          :page-sizes="[12, 50, 100, 200]"
          @current-change="handleCurrentChange"
          @size-change="handleSizeChange">
        </el-pagination>
      </div>
    </div>
    <!--举报处理隐藏域-->
    <el-dialog title="举报处理" :visible.sync="pageData.disposePanelStatus" size="tiny" width="60%" :before-close="handleCloseReportDisposePanel">
      <el-form ref="form.reportDispose" :model="form.reportDispose" label-width="80px">
        <el-form-item label="举报ID"><el-input v-model="form.reportDispose.reportId" disabled></el-input></el-form-item>
        <el-form-item label="举报人"><el-input v-model="form.reportDispose.reportUserName" disabled></el-input></el-form-item>
        <el-form-item label="举报类型">
          <el-radio-group v-model="form.reportDispose.reportType">
            <el-radio :label="1" disabled>举报提问</el-radio>
            <el-radio :label="2" disabled>举报回答</el-radio>
            <el-radio :label="3" disabled>举报评论</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="举报原因">
          <el-radio-group v-model="form.reportDispose.reportReason">
            <el-radio :label="6" disabled>垃圾公告营销</el-radio>
            <el-radio :label="5" disabled>不友善内容</el-radio>
            <el-radio :label="4" disabled>侮辱谩骂骚扰</el-radio>
            <el-radio :label="3" disabled>淫秽色情信息</el-radio>
            <el-radio :label="2" disabled>违法有害信息</el-radio>
            <el-radio :label="1" disabled>涉嫌抄袭/盗用</el-radio>
            <el-radio :label="0" disabled>其它</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="举报内容">
          <el-input type="textarea" v-model="form.reportDispose.reportTargetTitle" autosize disabled></el-input>
        </el-form-item>
        <el-form-item label="处理状态">
          <el-radio-group v-model="form.reportDispose.reportStatus">
            <el-radio :label="0">未审核</el-radio>
            <el-radio :label="1">已审核</el-radio>
            <el-radio :label="2">已处理</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="处理方式">
          <el-radio-group v-model="form.reportDispose.reportProcessMode">
            <el-radio :label="0">仅阅读</el-radio>
            <el-radio :label="1">删除内容</el-radio>
            <el-radio :label="2">禁言3天</el-radio>
            <el-radio :label="3">禁言7天</el-radio>
            <el-radio :label="4">禁言30天</el-radio>
            <el-radio :label="5">终身禁言</el-radio>
            <el-radio :label="6">冻结账户</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="处理说明">
          <el-input type="textarea" v-model="form.reportDispose.reportReasonInfo" autosize></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="handleReportDisposeButtonClick">立即处理</el-button>
          <el-button @click="reportReasonStatus = false">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
  // 组件引入
  // 方法工具引入
  import { PermissionsToDetectFormUser } from '@/utils/PermissionsDetect';
  import { getPermission } from '@/utils/UserCookies';
  // 接口引入
  import { loadCmsReportList,saveCmsReportDisposeData } from "@/api/config";
  export default {
    name: "report",
    //import引入的组件需要注入到对象中才能使用
    components: {},
    data() {
      return {
        pageData:{
          searchReasonList: [
            {label: "请选择举报原因", value: -1},
            {label: "垃圾公告营销", value: 6},
            {label: "不友善内容", value: 5},
            {label: "侮辱谩骂骚扰", value: 4},
            {label: "淫秽色情信息", value: 3},
            {label: "违法有害信息", value: 2},
            {label: "涉嫌抄袭/盗用", value: 1},
            {label: "其它", value: 0}
          ],
          searchStatusList: [
            {label: "请选择处理结果", value: -1},
            {label: "未审核", value: 0},
            {label: "已审核", value: 1},
            {label: "已处理", value: 2}
          ],
          searchTypeList: [
            {label: "请选择被举报类型", value: -1},
            {label: "举报问题", value: 1},
            {label: "举报回答", value: 2},
            {label: "举报评论", value: 3}
          ],
          loading: false,
          disposePanelStatus: false
        },// 页面配置数据
        form:{
          searchReason: -1,
          searchStatus: -1,
          searchType: -1,
          pageNum: 1,
          pageSize: 12,
          total: 0,
          selection: [],
          reportDispose: {}
        },// 页面表单
        formRules: {},// 表单验证
        responseData: {
          tableList: []
        },// 接口响应数据
      }
    },
    //监听属性 类似于data概念
    computed: {},
    //监控data中的数据变化
    watch: {},
    //方法集合
    methods:{
      // 事件函数
      handlePageInit(){
        this.pageData.loading = true;// 创建加载窗口
        this.loadCmsReportList();// 读取路由角色列表
      },// 页面初始化事件
      handleCurrentChange(val){
        this.form.pageNum = val;// 更换页码
        this.handlePageInit();// 进行数据加载
      },// 页码切换事件
      handleSizeChange(val){
        this.form.pageSize = val;// 更换页面大小
        this.handlePageInit();// 进行数据加载
      },// 页面size切换事件
      handleTableSelection(val){
        let list = [];// 初始化多选数组
        for (let i=0; i<val.length; i++){
          list.push(val[i].reportId);
        }// 遍历多选的列表，将ID拼入数组中
        this.form.selection = list;// 进行多选值的切换
      },// 表格多选事件
      handleOpenReportDisposePanel(scope){
        this.pageData.disposePanelStatus = true;
        this.form.reportDispose = scope.row;
      },// 处理举报按钮点击事件
      handleCloseReportDisposePanel(){
        this.$confirm('确认关闭？').then(response => {
          // 初始化表单
          this.form.reportDispose = {
            reportId: '',
            reportType: 0,
            reportStatus: 0,
            reportReason: 0,
            reportProcessMode: 0,
            reportUserName: '',
            reportTargetTitle: '',
            reportReasonInfo: ''
          };
          // 关闭面板
          this.pageData.disposePanelStatus = false;
        }).catch(err => {
          console.log(err);
        });
      },// 关闭处理面板
      handleReportDisposeButtonClick(){
        this.$confirm('是否对此举报内容进行处理, 请核对后继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.saveCmsReportDisposeData();
        }).catch(close => {
          console.log(close);
          this.$message.info("已取消操作");
        });
      },// 保存处理状态按钮点击事件
      // 接口
      loadCmsReportList(){
        loadCmsReportList(this.form).then(response => {
          if (response.code === "200"){
            this.pageData.loading = false;
            this.responseData.tableList = response.data.list;
            this.form.total = response.data.total;
          } else {
            this.$message.warning(response.message);
          }
        }).catch( error =>{
          console.log(error);
          this.$message.error(error);
        })
      },// 获取表格数据
      saveCmsReportDisposeData(){
        saveCmsReportDisposeData(this.form.reportDispose).then(response => {
          if (response.code === "200"){
            this.$message.success("举报处理成功");
            this.pageData.disposePanelStatus = false;
            this.handlePageInit();
          } else {
            console.log(response.message);
          }
        }).catch(error => {
          console.log(error);
        })
      },// 保存处理状态
    },
    //生命周期 - 创建完成（可以访问当前this实例）
    created: function () {
      let _this = this;
      setTimeout(function () {
        _this.handlePageInit();
      }, 800);
    },
    //生命周期 - 挂载完成（可以访问DOM元素）
    mounted() {},
    beforeCreate() {}, //生命周期 - 创建之前
    beforeMount() {}, //生命周期 - 挂载之前
    beforeUpdate() {}, //生命周期 - 更新之前
    updated() {}, //生命周期 - 更新之后
    beforeDestroy() {}, //生命周期 - 销毁之前
    destroyed() {}, //生命周期 - 销毁完成
    activated() {}, //如果页面有keep-alive缓存功能，这个函数会触发
  };
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
</style>
